<?php
require_once 'smarty/Smarty.class.php';
/*
 * add by ngannv
 * @DATE : update 20.08.11
 * */
class jSmarty extends Smarty
{

    public function __construct()
    {
        $this->compile_dir = (!empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir']
                : APPPATH . '/cache/');
        $this->template_dir = (!empty($config['smarty_template_dir']) ? $config['smarty_template_dir']
                : APPPATH . '/views/');
        $this->caching = false;
    }

    public function setVar($var_tpl, $var_php = '')
    {
        $this->assign($var_tpl, $var_php);
    }

    /*
     * ngannv add 20.08.2011
     * Display tempLate
     * */
    public function viewTemplate($tpl_file, $vars = null, $clear_flag = false)
    {
        if ($clear_flag) {
            $this->clearAllAssign();
        }
        $vars['base_url'] = BASE_URL;
        if (!isset($vars['title'])) {
            $vars['title'] = APP_NAME;
        }
        if ($vars != null) {
            foreach ($vars as $key => $value) {
                $this->assign($key, $value);
            }
        }
        $this->display($tpl_file, $vars);
    }

    /*
     * ngannv update 20.08.2011
     * getTemplate
     * */
    public function getTemplate($tpl_file, & $vars = null, $clear_flag = 0)
    {
        if ($clear_flag) {
            $this->clearAllAssign();
        }
        try {
            if (is_array($vars)) {
                foreach ($vars as $key => $value) {
                    $this->assign($key, $value);
                }
            }
            return $this->fetch($tpl_file);
        } catch (ViewException $e) {
            throw new ViewException($e->getMessage());
        }
    }
}